package com.tledu.zyf.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

public class PasswordFilter implements Filter {
	String password;

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		password = filterConfig.getServletContext().getInitParameter("password");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		String pass = request.getParameter("password");
		if (password.equals(pass)) {
			chain.doFilter(request, response);
		} else {
//			if (response instanceof HttpServletResponse) {
//				HttpServletResponse hsResponse = (HttpServletResponse) response;
//				hsResponse.sendRedirect("");
//			}
			request.setAttribute("msg", "密码不正确 ! ");
			request.getRequestDispatcher("/login.jsp").forward(request, response);
		}

	}

	@Override
	public void destroy() {

	}

}
